package com.example.demo.leetcode.classics150;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _119寻找旋转排序数组中的最小值
 * @description
 * @date 2023/08/16 20:30
 * <p>
 * ******************************************************
 */
public class _119寻找旋转排序数组中的最小值 {

    public int findMin(int[] nums) {
        int lo = 0;
        int hi = nums.length - 1;
        int mid;
        int min = Integer.MAX_VALUE;
        while (lo <= hi) {
            mid = hi - (hi - lo) / 2;
            if (nums[mid] >= nums[lo]) {
                min = Math.min(min, nums[lo]);
                lo = mid + 1;
            } else {
                min = Math.min(min, nums[mid]);
                hi = mid - 1;
            }
        }

        return min;
    }
}
